home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Subject: Re: What`s so different a
- X-Nntp-Posting-Host: golden.ripco.com
- Message-ID: <DKJC8u.J2F@rci.ripco.com>
- Sender: usenet@rci.ripco.com (Net News Admin)
- Organization: Ripco Internet BBS Chicago
- Date: Tue, 2 Jan 1996 03:55:42 GMT
- X-Ident-Sender: mambuhl
-
- mark@fredblog.demon.co.uk (Mark Winfield)
- in <820451938.20697@fredblog.demon.co.uk> asks:
-
- [code & comments at EOM]
-
- >This program does not work with a '.c' or '.cpp' extension. If I run
-
- More properly, it does not work as either a C or C++ program.
-
- >the program from dos I get well done and then something about NULL
- >pointers and the program hangs, so I have to reset. And if I run the
- >program from within the TURBO C++ enviroment the program hangs after
- >printing well done.
-
- You get NULL pointer problems because you are referring to memory never
- allocated. Changes are in the code below, marked with /* mha - .
-
- /* mha - fixed "//" syntax error below */
- /* My own chess recorder program */
-
- >#include <stdio.h>
- >#include <ctype.h>
-
- >/*Prototypes*/
- void setup(char pos[9][9]); /* mha - replaced pos[8][8], since you
- * refer to pos[8][8], and indices
- * start at 0. 0..8 has 9 values */
-
- int /* mha - replaced "void", main requires
- an int return type */ main()
- >{
- char pos[9][9]; /* mha - replaced pos[8][8] */
- > setup(pos);
- > printf("\nWell Done!!");
- return 0; /* mha - added */
- >}
-
- >void setup(char pos[9][9])
- { /* mha - replaced pos[8][8] */
- > int x, y;
- > pos[1][8] = pos[8][8] = 'r';
- > pos[2][8] = pos[7][8] = 'n';
- > pos[3][8] = pos[6][8] = 'b';
- > pos[1][1] = pos[8][1] = 'R';
- > pos[2][1] = pos[7][1] = 'N';
- > pos[3][1] = pos[6][1] = 'B';
- > for (x = 1; x < 9; x++) {
- > pos[x][7] = 'a';
- > pos[x][2] = 'A';
- > for (y = 3; y < 7; y++)
- > pos[x][y] = ' ';
- > }
- > pos[4][8] = 'q';
- > pos[5][8] = 'k';
- > pos[4][1] = 'Q';
- > pos[5][1] = 'K';
- >}
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-